﻿using LxBasic;

namespace LxCore
{
    public abstract class ArrayScalar
    {
        public abstract class Base : IZoneField<double>
        {
            protected FvZone Zone;
            public double[] InnArray;
            public double[] BouArray;
            public virtual void CheckCreate(FvZone zone)
            {
                this.Zone = zone;
                CheckCreator.ArrayStrict(ref BouArray, zone.BouFaces.Length);
            }
            public abstract ICellVarArr<double> GetInnCellVarArr();
            public abstract ICellVarArr<double> GetBouCellVarArr();
            public abstract IFaceVarArr<double> GetInnFaceVarArr();
            public abstract IFaceVarArr<double> GetBouFaceVarArr();
        }
        public class BaseCell : Base
        {
            public override void CheckCreate(FvZone zone)
            {
                base.CheckCreate(zone);
                CheckCreator.ArrayStrict(ref InnArray, zone.InnCells.Length);
            }
            public override ICellVarArr<double> GetInnCellVarArr()
            {
                return new VarArrBuider.Direct<double>(InnArray);
            }
            public override ICellVarArr<double> GetBouCellVarArr()
            {
                return new VarArrBuider.Direct<double>(BouArray);
            }
            public override IFaceVarArr<double> GetInnFaceVarArr()
            {
                return new VarArrBuider.InnFaceByAve(Zone, InnArray);
            }
            public override IFaceVarArr<double> GetBouFaceVarArr()
            {
                return new VarArrBuider.Direct<double>(BouArray);
            }
        }
        public class BaseFace : Base
        {
            public override void CheckCreate(FvZone zone)
            {
                base.CheckCreate(zone);
                CheckCreator.ArrayStrict(ref InnArray, zone.InnFaces.Length);
            }
            public override ICellVarArr<double> GetInnCellVarArr()
            {
                return new VarArrBuider.InnCellByAve(Zone, InnArray);
            }
            public override ICellVarArr<double> GetBouCellVarArr()
            {
                return new VarArrBuider.Direct<double>(BouArray);
            }
            public override IFaceVarArr<double> GetInnFaceVarArr()
            {
                return new VarArrBuider.Direct<double>(InnArray);
            }
            public override IFaceVarArr<double> GetBouFaceVarArr()
            {
                return new VarArrBuider.Direct<double>(BouArray);
            }

        }
    }
}
//public override ICellVarArr<double> GetCellVarArr(IIndexHost indexHost)
//{
//    if (indexHost is FvInner inn && inn.InZone == Zone)
//    {
//        return new VarArrBuider.InnCellByAve(inn.InZone, InnArray);
//    }
//    else if (indexHost is FvBound bou && bou.InZone == Zone)
//    {
//        return new VarArrBuider.Direct<double>(BouArray);
//    }
//    else
//    {
//        throw new InvalidDataException();
//    }
//}
//public override IFaceVarArr<double> GetFaceVarArr(IIndexHost indexHost)
//{
//    if (indexHost is FvInner inn && inn.InZone == Zone)
//    {
//        return new VarArrBuider.Direct<double>(InnArray);
//    }
//    else if (indexHost is FvBound bou && bou.InZone == Zone)
//    {
//        return new VarArrBuider.Direct<double>(BouArray);
//    }
//    else
//    {
//        throw new InvalidDataException();
//    }
//}
//public override ICellVarArr<double> GetCellVarArr(IIndexHost indexHost)
//{
//    if (indexHost is FvInner inn && inn.InZone == Zone)
//    {
//        return new VarArrBuider.Direct<double>(InnArray);
//    }
//    else if (indexHost is FvBound bou && bou.InZone == Zone)
//    {
//        return new VarArrBuider.Direct<double>(BouArray);
//    }
//    else
//    {
//        throw new InvalidDataException();
//    }
//}
//public override IFaceVarArr<double> GetFaceVarArr(IIndexHost indexHost)
//{
//    if (indexHost is FvInner inn && inn.InZone == Zone)
//    {
//        return new VarArrBuider.InnFaceByAve(inn.InZone, InnArray);
//    }
//    else if (indexHost is FvBound bou && bou.InZone == Zone)
//    {
//        return new VarArrBuider.Direct<double>(BouArray);
//    }
//    else
//    {
//        throw new InvalidDataException();
//    }
//}
//public struct BoundFaceVar<T> : IFaceVar<T>
//{
//    public BoundFaceVar(T[] array, int Offset_cell_face)
//    {
//        this.CellArray = array;
//        OffSet = Offset_cell_face;
//    }
//    public T[] CellArray;
//    public int OffSet;//cell-face
//    public T GetFaceValue(int faceID)
//    {
//        return CellArray[faceID + OffSet];
//    }
//}